<template>
  <div class="user-avatar-dropdown small-badge">
    <Dropdown  @on-click="handleClick">
      <Badge :dot="!!messageUnreadCount">
		  <span>我的</span>
        <!-- <Avatar :src="userAvatar"/> -->
      </Badge>
      <Icon :size="18" type="md-arrow-dropdown"></Icon>
      <DropdownMenu slot="list">
        <DropdownItem name="message">
          消息中心<Badge style="margin-left: 5px" :count="messageUnreadCount"></Badge>
        </DropdownItem>
        <DropdownItem name="loginpassw">
          修改登录密码
        </DropdownItem>
        <DropdownItem name="payforpassw">
          修改支付密码
        </DropdownItem>
        <DropdownItem name="logout">退出登录</DropdownItem>
      </DropdownMenu>
    </Dropdown>
  </div>
</template>

<script>
import './user.less'
import { mapActions } from 'vuex'
export default {
  name: 'User',
  props: {
    userAvatar: {
      type: String,
      default: ''
    },
    messageUnreadCount: {
      type: Number,
      default: 0
    }
  },
  methods: {
    ...mapActions([
      'handleLogOut'
    ]),
    logout () {
      this.handleLogOut().then(() => {
        this.$router.push({
          name: 'login'
        })
      })
    },
    message () {
      this.$router.push({
        name: 'message_page'
      })
    },
    loginpassw () {
      this.$router.push({
        name: 'loginpassw_page'
      })
    },
    payforpassw () {
      this.$router.push({
        name: 'payforpassw_page'
      })
    },
    handleClick (name) {
      switch (name) {
        case 'logout': this.logout()
          break
        case 'message': this.message()
          break
	    case 'loginpassw': this.loginpassw()
			break
		case 'payforpassw': this.payforpassw()
			break	
      }
    }
  }
}
</script>
<style>
  .small-badge .ivu-dropdown-item{
    text-align: center;
    padding: 8px 8px;
    font-size: 13px;
  }
  .small-badge .ivu-badge-count{
    height: 15px;
    border-radius: 100%;
    min-width: 15px;
    line-height: 12px;
    text-align: center;
    padding: 0 3px;
    font-size: 11px;
  }

</style>

</style>
